<?php defined("MAIN_DIR") or die("No direct access");

if ($route->POST("action") == "post"){

	$book_id = UV::rInt($route->POST("id"));
    $name = UV::rStr($route->POST("name"));
    $ozon = UV::rInt($route->POST("ozon"));
    $books = UV::rStr($route->POST("books"));

	$query = "update `books` set `name`='$name',`ozon`='$ozon',`books`='$books',`status`='placed' where `id` = '$book_id' limit 1";
	if ($db->sendQuery($query) !== false){
		to("/admin/books/edit/{$book_id}");
	} else {
		echo "Ошибка - ".mysql_error();
	}

} else {

	$query = "insert into `books` values(NULL,'{$user->id()}','','','','auto-draft')";
	$book_id = $db->sendQuery($query);
}

require_once ADMIN.HEADFILE;
?>

<h1>Добавить гостя</h1>

<form method='post' id='form'>
	<input type='hidden' name='action' value='post' />
	<input type='hidden' name='id' value='<?php echo $book_id; ?>' />
	<table class='edit'>
		<tr>
			<td class='label'><label for='name'>Название</label></td>
			<td>
				<input type="text" name="name" id="name" class='long' value="<?php echo $route->POST("name"); ?>" />
			</td>
		</tr>
        <tr>
			<td class='label'><label for='ozon'>OZON</label></td>
			<td>
				<input type="text" name="ozon" id="ozon" class='long' value="<?php echo $route->POST("ozon"); ?>" />
			</td>
		</tr>
        <tr>
			<td class='label'><label for='books'>Books</label></td>
			<td>
				<input type="text" name="books" id="books" class='long' value="<?php echo $route->POST("books"); ?>" />
			</td>
		</tr>
		<tr>
			<td class='label' colspan='2'>
				<input type='submit' value='Добавить книгу' class='button' />
			</td>
		</tr>
	</table>
</form>

<?php require_once ADMIN.FOOTERFILE; ?>